<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.org/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
</head>
<body>
<script src="/resources/layui/layui.js"></script>

<script th:inline="none">
    //一般直接写在一个js文件中
    layui.use(['layer', 'form','table'], function(){
        var layer = layui.layer
            ,form = layui.form
            ,table = layui.table
            ,$=layui.jquery;
        //表单提交
        $("#btn_add").click(function () {
            console.log("----")
            $.ajax({
                type:'post',
                url:'user/useradds',
                data:$("#supAddForm").serialize(),
                success:function () {
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭当前页
                    //刷新父类页面
                    window.parent.location.reload()

                }
            })
        })
        //部门下拉菜单
        $.ajax({
            type:'get',
            url:'/dept/depts',
            success:function (res) {
                var depts=res.data.depts;
                if(depts.length>0){
                    for(var i=0;i<depts.length;i++){
                        var dept=depts[i];
                        $("#deptid").append("<option value='"+dept.id+"'>"+dept.name+"</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select")
            }
        })
        //职位下拉菜单
        $.ajax({
            type:'get',
            url:'/dictionary/selectEmpByType',
            success:function (res) {
                var emps=res.data.dictionaries;
                if(emps.length>0){
                    for(var i=0;i<emps.length;i++){
                        var emp=emps[i];
                        $("#position").append("<option value='"+emp.id+"'>"+emp.name+"</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select")
            }
        })
    });
</script>
<form class="layui-form" action="" id="supAddForm">
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-block">
            <input type="text" name="telephone" required  lay-verify="required" placeholder="请输入电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">生日</label>
        <div class="layui-input-inline">
            <input type="Date" name="birthday" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-block">
            <select id="deptid" name="dept" lay-verify="required">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="男" title="男" checked>
            <input type="radio" name="sex" value="女" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <select id="position" name="positionid" lay-verify="required">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">入职时间</label>
        <div class="layui-input-inline">
            <input type="Date" name="entry" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="statues" value="1"  title="在职" checked>
            <input type="radio" name="statues" value="0" title="休假">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            <input type="radio" name="available" value="1" title="启用"  checked>
            <input type="radio" name="available" value="0" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <!--<button class="layui-btn" lay-submit lay-filter="formDemo" id="btn_add">立即提交</button>-->
            <input type="button" class="layui-btn" id="btn_add" value="立即提交">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

</body>
</html>